import threading
import sys
from sys import stdin
input=stdin.readline
sys.setrecursionlimit(10**8)
from collections import defaultdict
def main():
n=int(input())
graph=[[] for _ in range(n)]
degree=[0]*(n)
for _ in range(n-1):
a,b=map(int,input().split())
a-=1
b-=1
degree[a]+=1
degree[b]+=1
graph[a].append(b)
graph[b].append(a)
start=max(degree)
for i,el in enumerate(degree):
if el==start:
start=i
break
res=[0]*(n)
def solve(node,p1):
curr=1
for nie in graph[node]:
if nie !=p1:
while res[node]==curr or res[p1]==curr:
curr+=1
res[nie]=curr
solve(nie,node)
curr+=1
res[start]=1
solve(start,start)
print(len(set(res)))
print(*res)
threading.stack_size(10 ** 8)
t = threading.Thread(target=main)
t.start()
t.join()
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#include <stack>
#include <cmath>
#include <string>
#include <cstring>
#include <set>
using namespace std;
const int mod=1e9+7;
#define ll long long int
void addEdge(vector<int> adj[], int u, int v)
{
adj[u].push_back(v);
adj[v].push_back(u);
}
void BFS_root(vector<int> adj[], vector<int> &visited , vector<int>&parent, vector<int>&dist, int V, int s,vector<int>&col){
queue<int> bfs; bfs.push(s); dist[s]=0; visited[s]=1; col[1]=1;
while (!bfs.empty()) {
int u = bfs.front();
bfs.pop(); int ct=1;
for(int i=0;i<adj[u].size();i++){
if(visited[adj[u][i]]==-1){
visited[adj[u][i]]=1; parent[adj[u][i]]=u; dist[adj[u][i]]=dist[u]+1;int x=adj[u][i];
bfs.push(adj[u][i]);
// cout << adj[u][i] << " pushed\n";
// print_queue(bfs);
if(ct!=col[u] && u!=1 && ct!=col[parent[u]]) col[x]=ct++;
else if(ct!=col[u] && u==1) col[x]=ct++;
else if(ct==col[u] && u==1) {col[x]=ct+1;ct+=2;}
else if(ct==col[u] && u!=1 && ct==col[parent[u]]) {col[x]=ct+1;ct+=2;}
else if(u!=1){
if(ct==col[u] && ct+1==col[parent[u]]) {col[x]=ct+2;ct=col[x]+1;}
else if(ct+1==col[u] && ct==col[parent[u]]) {col[x]=ct+2;ct=col[x]+1;}
else {col[x]=ct+1;ct=col[x]+1;}
}
}
}
}
}
void BFS_main(vector<int> adj[], vector<int> &visited , vector<int>&parent, vector<int>&dist, int V,vector<int>&col){
for(int i=0;i<V;i++){visited.push_back(-1);}
for(int i=0;i<V;i++){parent.push_back(-1);}
for(int i=0;i<V;i++){dist.push_back(-1);}
BFS_root(adj,visited ,parent,dist,V,1,col);
// for(int i=0;i<V;i++) {
// if(visited[i]==-1) {BFS_root(adj,visited ,parent,dist,V,i);}
// }
}
int main(){
int n;cin>>n; vector<int>adj[n+1];
for(int i=0;i<n-1;i++){
int a,b; cin >>a>>b; addEdge(adj,a,b);
}
vector<int> visited; vector<int> parent; vector<int> dist; vector<int>col(n+1);
BFS_main(adj,visited,parent,dist,n+1,col);
col[0]=-1;int sm=0;
for(int i=1;i<=n;i++) sm=max(sm,col[i]);
cout << sm << endl;
for(int i=1;i<=n;i++) cout<<col[i]<< " ";cout<<endl;
}
1302. Deepest Leaves Sum | 1209. Remove All Adjacent Duplicates in String II |
994. Rotting Oranges | 983. Minimum Cost For Tickets |
973. K Closest Points to Origin | 969. Pancake Sorting |
967. Numbers With Same Consecutive Differences | 957. Prison Cells After N Days |
946. Validate Stack Sequences | 921. Minimum Add to Make Parentheses Valid |
881. Boats to Save People | 497. Random Point in Non-overlapping Rectangles |
528. Random Pick with Weight | 470. Implement Rand10() Using Rand7() |
866. Prime Palindrome | 1516A - Tit for Tat |
622. Design Circular Queue | 814. Binary Tree Pruning |
791. Custom Sort String | 787. Cheapest Flights Within K Stops |
779. K-th Symbol in Grammar | 701. Insert into a Binary Search Tree |
429. N-ary Tree Level Order Traversal | 739. Daily Temperatures |
647. Palindromic Substrings | 583. Delete Operation for Two Strings |
518. Coin Change 2 | 516. Longest Palindromic Subsequence |
468. Validate IP Address | 450. Delete Node in a BST |